Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

613 Fix CqlComparer for tuples #614

Open
wants to merge 21 commits into
base: develop-2.0
Choose a base branch
from

Conversation

baseTwo
Copy link
Collaborator

@baseTwo baseTwo commented Oct 18, 2024

Fix for

Work

  • Replaced TupleComparer with CqlTupleTypeComparer. The new comparer compares value tuples where the first parameter is of type CqlTupleMetadata and uses the metadata to compare items.
  • The legacy TupleBaseTypeComparer cannot be removed yet, since some unit tests still execute against directly compiled LambdaExpressions, instead of going through the C# code writer and assembly compiled.
  • CqlTupleMetadata had to be moved to a more base project and was moved from Hl7.Cql.Runtime' to Hl7.Cql.Primitives`
  • TypeExtensions had to move to a more base project too, and was moved from Hl7.Cql.Compiler to Hl7.Cql.Primitives. The extensions for this particular TypeExtensions is for types related to CQL.
  • Added unit test TypeExtensionsTests
  • Relevant unit tests from CoreTests were moved into subfolders so it is clear from which project they belong to
  • A few places in the repo uses a property-name/property-type tuple. Sometimes the type is placed first, other times the name. This was made consistent so the type is always first.

Integration Runner

While working on this PR, I also looked at the integration tests for CMS measure. I found they were flaky, due to the libraries sometimes failing to create. This was due to the CqlTupleMetadata calculating the hashcode in the constructor, and that used Hasher.Instance which uses MD5 to hash a string. For some strange reason, a NullReferenceException is sometimes thrown deep inside the stack trace. I changed the CqlTupleMetadata to do hash calculation lazily.

I also discovered that the KeyValuePairComparer<TKey,TValue> comparer fails when TValue is an object when doing a compare. An error is thrown stating that 'object' is not comparable. I fixed this by using the ICqlComparer on key and value instead.

Test pass rate increased from 68% to 72%

…mpiler' into 613-fix-integration-test---systemargumentexception-cannot-generate-a-hash-code-for-valuetuple3-arg_paramname_name
…mpiler' into 613-fix-integration-test---systemargumentexception-cannot-generate-a-hash-code-for-valuetuple3-arg_paramname_name
@baseTwo baseTwo changed the base branch from develop-2.0 to 615-change-unit-tests-to-compile-and-run-via-assemblycompiler October 21, 2024 16:24
@baseTwo baseTwo marked this pull request as ready for review October 21, 2024 16:32
Base automatically changed from 615-change-unit-tests-to-compile-and-run-via-assemblycompiler to develop-2.0 October 22, 2024 14:12
{
0 => Comparer<TValue>.Default.Compare(x.Value, y.Value),
0 => cqlComparer.Compare(x.Value, y.Value, precision),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a bug, the fact that precision wasn't passed on to the compare?

Copy link
Collaborator Author

@baseTwo baseTwo Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .NET Comparer wasn't capable of taking a precision. This was replaced with the ICqlComparer, it would make sense to use precision on KeyValuePair's Value property.

cc @EvanMachusak

Copy link
Member

@ewoutkramer ewoutkramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a few questions to double check. Could the change made by passing on precision create regressions for HEDIS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants